<div th:replace="~{ app :: layout ('maven 加速，修改镜像源', ~{::#css}, _, ~{::#main}, ~{::#js}) }" xmlns:th="http://www.thymeleaf.org">
    <div id="css">
        <link href="vendor/vditor/dist/index.css" rel="stylesheet">
        <link rel="stylesheet" href="vendor/tocbot/dist/tocbot.css">
    </div>

    <section class="single-post container" id="main">
        <div class="row">
            <div class="col-lg-8">
                <h1 class="title">maven 加速，修改镜像源</h1>
                <p class="meta text-muted">
                    <a href="#">ddd</a>
                    <span> - </span>
                    2023-06-11 14:59:23
                    <span> - </span>
                    <a href="#5"
                       class="badge badge-light font-weight-normal text-muted p-1">maven</a>
                    <a href="#"
                       class="badge badge-light font-weight-normal text-muted p-1">镜像源</a>
                </p>
                <div id="vditor-preview-element" class="markdown-body js-toc-content animate__animated animate__fadeInLeft">
                    <div class="d-none" id="content">### 为什么慢
执行 mvn 各种命令的时候，默认是去 maven 官方镜像源获取需要安装的具体软件信息

默认源地址在国外，从国内访问的速度肯定比较慢

### 如何修改镜像源
阿里巴巴维护着一个国内 maven 镜像源

#### a). 配置只在当前项目生效

在 pom.xml 文件内添加以下配置

```xml
&lt;repositories&gt;
&lt;repository&gt;
&lt;id&gt;ali-maven&lt;/id&gt;
&lt;url&gt;http://maven.aliyun.com/nexus/content/groups/public&lt;/url&gt;
&lt;/repository&gt;
&lt;/repositories&gt;
```
#### b). 配置全局生效

修改 settings.xml 文件

找到 &lt;mirrors&gt; 标签，在里面加入以下内容

```xml
&lt;mirror&gt;
&lt;id&gt;alimaven&lt;/id&gt;
&lt;name&gt;aliyun maven&lt;/name&gt;
&lt;url&gt;http://maven.aliyun.com/nexus/content/groups/public/&lt;/url&gt;
&lt;mirrorOf&gt;central&lt;/mirrorOf&gt;
&lt;/mirror&gt;
```

可以在以下路径查找到 settings.xml 文件

1. (用户家目录)/.m2/settings.xml

2. (maven安装目录)/conf/settings.xml，

如果是 Mac 系统通过 brew 命令安装的，在这里：

/usr/local/Cellar/maven/(版本号)/libexec/conf/settings.xml
                    </div>
                </div>
            </div>

            <div class="col-lg-3 offset-lg-1">
                <div id="outline" class="js-toc toc sticky-top d-none d-lg-block animate__animated animate__fadeInRight animate__delay-1s"></div>
            </div>
        </div>
    </section>

    <div id="js">
        <script src="vendor/tocbot/dist/tocbot.js"></script>
        <script src="vendor/vditor/dist/method.min.js"></script>
        <script>
            Vditor.preview(document.getElementById('vditor-preview-element'), document.getElementById('content').textContent,
                {
                    cdn: 'vendor/vditor',
                    theme: {
                        path: 'vendor/vditor/dist/css/content-theme',
                    },
                    lazyLoadImage: 'vendor/vditor/dist/images/img-loading.svg',
                    after () {
                        tocbot.init({
                            // Where to render the table of contents.
                            tocSelector: '.js-toc',
                            // Where to grab the headings to build the table of contents.
                            contentSelector: '.js-toc-content',
                            // Which headings to grab inside of the contentSelector element.
                            headingSelector: 'h1, h2, h3, h4, h5, h6',
                            // For headings inside relative or absolute positioned containers within content.
                            hasInnerContainers: false,
                            collapseDepth: 6,
                        });
                        $(".js-toc a.toc-link").mouseover(function () {
                            $(this).attr('title', $(this).text());
                        });
                        $('.js-toc a.toc-link').on('click', function(e){
                            //store hash
                            const href = $(this).attr("href");
                            const hash = href.substr(href.indexOf("#"));
                            // animate
                            $(hash).animateCss('slow');
                            $(hash).animateCss('flash');
                        });
                    },
                }
            );
        </script>
    </div>
</div>
